<template>
	<view>
		<!-- #ifdef MP-WEIXIN -->
		<view class="ad_wrap">
			<common-ad unitId="adunit-a607e0cd56336b45" adType="custom" />
		</view>
		<!-- #endif -->
		<view class="uni-list-cell solid-bottom" hover-class="uni-list-cell-hover" v-for="(item, index) in expressWdList"
			:key="item.id">
		
			<view style="display: flex;">
				<!-- <view class="topTitleV">{{item.name}}</view> -->
				<rich-text :nodes="item.name"></rich-text>
				<view
					class="rigFlagV">
					{{item.companyName}}
				</view>
			</view>
		
		
			<view style="display: flex;">
				<view class="titleV">地址:</view>
				<view class="detailV">{{item.xzqFullName}} {{item.address}}</view>
				<view class="padding-sm" @click="copyText(item.xzqFullName + item.address)">
					<text class="cuIcon-copy"></text>
				</view>
			</view>
		
			<view style="display: flex;">
				<view class="titleV">联系电话:</view>
				<view class="detailV" style="color: #1890FF; margin-top: 2px; line-height: 22px; align-self: center;">{{item.mobile || item.tel}}</view>
				<view class="padding-sm" @click="copyText(item.mobile || item.tel)">
					<text class="cuIcon-copy"></text>
				</view>
			</view>
		
		
			<view style="display: flex;">
				<view class="titleV">网点编码:</view>
				<view class="detailV">{{item.number}}</view>
			</view>
		
		</view>
		<!-- #ifdef MP-WEIXIN -->
		<view class="ad_wrap" v-if="expressWdList && expressWdList.length > 5">
			<common-ad unitId="adunit-ab16e48dff5c5069" adType="video" />
		</view>
		<!-- #endif -->
	</view>
</template>

<script>
	import { mapState, mapActions } from 'vuex';
	import {expressCompanyListQueryByPosition} from "../../controller/request_ctrl";
	const expressData = uniCloud.importObject('getExpressData');
	
	export default {
		data() {
			return {
				expressWdList: [],
				expressAddress: '',
				expressCom: '',
				pageIndex: -1
			}
		},
		onLoad(options) {
			// 需要去掉市辖区，不然接口不认地址
			this.expressAddress = options.expressAddress.replace('市辖区', '');
			this.expressCom = options.expressCom;
			this.queryData();
			this.isLastPage = false;
		},
		// 页面滚动到底
		onReachBottom() {
			if (this.isLastPage) {
				return;
			}
			this.queryData();
		},
		methods: {
			queryData() {
				this.pageIndex += 1;
				console.log('---- expressWdList queryData ----', this.expressAddress, this.expressCom, this.pageIndex);
				expressData.getWd(this.expressCom, this.expressAddress, this.pageIndex).then((res) => {
					console.log('---- expressData.getWd ----:', res)
					const resObj = JSON.parse(res);
					if (resObj.status === 200) {
						if (!resObj.netList) {
							uni.showToast({
								icon: 'none',
								title: resObj.message ? resObj.message : '数据拉取失败，请稍后再试',
								duration: 2500
							})
							return;
						}
						if (resObj.netList.length === 0) {
							if (this.expressWdList.length === resObj.total) {
								this.isLastPage = true;
							}
							uni.showToast({
								icon: 'none',
								title: this.pageIndex >= 2 ? '没有更多数据了' : '暂无数据',
								duration: 2500
							})
							return;
						}
						this.expressWdList.push(...resObj.netList);
						if (this.expressWdList.length === resObj.total) {
							this.isLastPage = true;
						}
						return;
					}
					uni.showToast({
						icon: 'none',
						title: resObj.message ? resObj.message : '数据拉取失败，请稍后再试',
						duration: 2500
					})
				})
				// expressCompanyListQueryByPosition(this.expressAddress, this.expressCom, this.pageIndex).then((res) => {
				// 	console.log('---- expressCompanyListQueryByPosition ----', res);
				// 	if (res.showapi_res_code === 0) {
				// 		if (!res.showapi_res_body.contentlist) {
				// 			uni.showToast({
				// 				icon: 'none',
				// 				title: res.showapi_res_body.msg,
				// 				duration: 2500
				// 			})
				// 			return;
				// 		}
				// 		if (res.showapi_res_body.contentlist.length === 0) {
				// 			uni.showToast({
				// 				icon: 'none',
				// 				title: this.pageIndex >= 2 ? '没有更多数据了' : '暂无数据',
				// 				duration: 2500
				// 			})
				// 			return;
				// 		}
				// 		this.expressWdList.push(res.showapi_res_body.contentlist);
				// 		return;	
				// 	}
				// 	uni.showToast({
				// 		icon: 'none',
				// 		title: res.showapi_res_error,
				// 		duration: 2500
				// 	})
				// })
			},
			copyText(text) {
				uni.setClipboardData({
					data: text,
					success: function () {
						uni.showToast({
							title: "复制成功",
							icon: 'none'
						})
					},
					fail: function() {
						uni.showToast({
							title: "复制失败,可手动选择复制",
							icon: 'none'
						})
					}
				})
			}
		}
	}
</script>

<style scoped>
	.uni-list-cell {
		flex-direction: column;
		margin-top: 10px;
		background-color: white;
		padding: 8px 12px;
	}

	.topTitleV {
		align-items: center;
		height: 36px;
		width: calc(100vw - 28px - 66px);
		align-self: center;
		color: #333333;
		font-weight: 500;
		font-size: 16px;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.rigFlagV {

		display: flex;
		border-radius: 5px;
		border: 1rpx solid #1890FF;
		color: #1890FF;
		text-align: center;
		align-self: center;
		font-size: 10px;
		height: 22px;
		line-height: 22px;
		padding: 0px 3px;
		margin-left: 5px;
	}


	.cellView {
		margin-top: 8px;
		margin-left: 8px;
		height: 22px;
		line-height: 22px;
		text-align: center;
		border-radius: 2px;
		padding: 0px 4px !important;
		font-size: 12px;

		color: #1890FF;
		background: #F3F4F6;
	}

	.titleV {
		color: #888888;
		font-size: 12px;
		height: 26px;
		line-height: 26px;
		white-space: nowrap;
		flex: none;
	}

	.detailV {
		margin-left: 4px;
		color: #333333;
		font-size: 13px;
		height: auto;
		line-height: 26px;
		width: calc(100vw - 108px);
		user-select: text;
	}
</style>
